package core.genetic.mutation.single;

import static java.lang.Math.*;

import java.util.Random;

import utility.Utils;

/**
 * Mutation with normal distribution pn' =pn+sigma*Nn(0,1)
 * 
 * @author pjovanovic05
 * 
 */
public class NormalMutation implements SingleGeneMutation
{

	private double normalDist()
	{
		Random r = Utils.random;
		double a = r.nextDouble();
		double b = r.nextDouble();

		double c = sqrt(-1 * log(a)) * cos(2 * PI * b);
		// double d = sqrt(-2 * log(a)) * sin(2 * PI * b);
		return c;
	}

	@Override
	public double getMutated(double oldValue) {
		return max(-1, min(1,oldValue + Utils.random.nextGaussian()));
	}

}
